package com.shenmazong.thread;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: server-java-demo
 * @description: ThreadArrayListTest1
 * @author: 亮子说编程
 * @create: 2020-10-20 14:43
 **/

class ChatMessageRunable implements Runnable {

    @Override
    public void run() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ThreadArrayListTest1.list.add(Thread.currentThread().getName());
        System.out.println(Thread.currentThread().getName());
    }
}
public class ThreadArrayListTest1 {
    public static volatile List list = new ArrayList();

    public static void main(String[] args) throws InterruptedException {
        for (int idx = 0; idx < 10; idx++) {
            new Thread(new ChatMessageRunable()).start();
        }

        Thread.sleep(1000*10);

        System.out.println(list.size());
    }
}
